home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (PowerPlant, Game) 1.2 / AcereÄ.sit / Acereƒ / Code / AcereApp.cp next >
Text File  |  1995-03-04  |  8KB  |  309 lines

  1. // ===========================================================================
  2. //    AcereApp.cp                    ⌐1994 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    A simple Application class which manages text documents.
  6.  
  7. #include "AcereApp.h"
  8. #include "CTextDoc.h"
  9. #include "CardWell.h"
  10. #include "CardDeck.h"
  11.  
  12. #include "WellDeck.h"
  13. #include "WellFreeCell.h"
  14. #include "WellStack.h"
  15.  
  16. #include <LApplication.h>
  17. #include <LGrowZone.h>
  18. #include "CardWindow.h"
  19. #include <LScroller.h>
  20. #include <LPrintout.h>
  21. #include <LPlaceHolder.h>
  22. #include <LDialogBox.h>
  23. #include <LCaption.h>
  24. #include <LStdControl.h>
  25. #include <UReanimator.h>
  26.  
  27. #include <UMemoryMgr.h>
  28. #include <UDrawingState.h>
  29. #include <UPowerTools.h>
  30. #include <URegistrar.h>
  31. #include <UDesktop.h>
  32.  
  33. #include <Balloons.h>
  34.  
  35.             AcereApp    *theApp;
  36. extern        CTextDoc    *theDoc;
  37.  
  38. unsigned long            ourAvailRam;
  39. const MessageT            pressedOK    = 2001;
  40.  
  41. // ===========================================================================
  42. //        Ñ Main Program
  43. // ===========================================================================
  44.  
  45. void main(void)
  46. {
  47.                                     // Set Debugging options
  48. #ifdef Debug_Throw
  49.     gDebugThrow = debugAction_Alert;
  50. #endif
  51.  
  52. #ifdef Debug_Signal
  53.     gDebugSignal = debugAction_Alert;
  54. #endif
  55.  
  56.     InitializeHeap(3);                // Initialize Memory Manager
  57.                                     // Parameter is number of Master Pointer
  58.                                     //   blocks to allocate
  59.     
  60.                                     // Initialize standard Toolbox managers
  61.     UQDGlobals::InitializeToolbox(&qd);
  62.     
  63. #ifdef Debug_Signal                    // Check for missing MBAR, which
  64.     CheckForInitialMBAR();            // probably means that there is no
  65. #endif                                // project resource file
  66.     
  67.     
  68.     new LGrowZone(20000);            // Install a GrowZone function to catch
  69.                                     //    low memory situations.
  70.                                     //    Parameter is size of reserve memory
  71.                                     //    block to allocated. The first time
  72.                                     //    the GrowZone function is called,
  73.                                     //    there will be at least this much
  74.                                     //    memory left (so you'll have enough
  75.                                     //    memory to alert the user or finish
  76.                                     //    what you are doing).
  77.     
  78. /*    if (!LDragAndDrop::DragAndDropIsPresent())
  79.     {
  80.         UDesktop::Deactivate();
  81.         ::Alert(10000, nil);
  82.         UDesktop::Activate();
  83.     }
  84.     else
  85. */    {
  86.         theApp = new AcereApp;            // Create instance of your Application
  87.         theApp->Run();
  88.     }
  89. }
  90.  
  91.  
  92. // ===========================================================================
  93. //        Ñ AcereApp Class
  94. // ===========================================================================
  95.  
  96. // ---------------------------------------------------------------------------
  97. //        Ñ AcereApp
  98. // ---------------------------------------------------------------------------
  99. //    Constructor
  100.  
  101. AcereApp::AcereApp()
  102. {
  103.     short    i;
  104.  
  105.     theDoc = ourDoc = nil;
  106.     balloonsActive = HMGetBalloons();
  107.     
  108.     aboutBox = nil;
  109.     
  110.     for (i=0; i<4; i++)                            //    load up the patterns
  111.     {
  112.         suitPats[i][0] = GetCIcon(1000+i);
  113.         suitPats[i][1] = GetCIcon(1100+i);
  114.     }
  115.  
  116.         // Register classes for objects created from 'PPob' resources
  117.     URegistrar::RegisterClass('wind', (ClassCreatorFunc) CardWindow::CreateCardWindowStream);
  118. //    URegistrar::RegisterClass(LWindow::class_ID,         LWindow::CreateWindowStream);
  119.     URegistrar::RegisterClass(LStdButton::class_ID,         LStdButton::CreateStdButtonStream);
  120. //    URegistrar::RegisterClass(LButton::class_ID,         LButton::CreateButtonStream);
  121.     URegistrar::RegisterClass(LDialogBox::class_ID,         LDialogBox::CreateDialogBoxStream);
  122.     URegistrar::RegisterClass(LCaption::class_ID,         LCaption::CreateCaptionStream);
  123.  
  124.     URegistrar::RegisterClass('scrl', (ClassCreatorFunc) LScroller::CreateScrollerStream);
  125. //    URegistrar::RegisterClass('Dtxt', (ClassCreatorFunc) CDirtyText::CreateDirtyTextStream);
  126.     URegistrar::RegisterClass('plac', (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
  127.     URegistrar::RegisterClass('prto', (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
  128.     URegistrar::RegisterClass('view', (ClassCreatorFunc) CardWell::CreateCardWell);
  129.     URegistrar::RegisterClass('CWwl', (ClassCreatorFunc) WellFreeCell::CreateWellFreeCell);
  130.     URegistrar::RegisterClass('CWdk', (ClassCreatorFunc) WellStack::CreateWellStack);
  131.     URegistrar::RegisterClass('CWst', (ClassCreatorFunc) WellDeck::CreateWellDeck);
  132.     
  133.     
  134.     
  135. }
  136.  
  137. // ---------------------------------------------------------------------------
  138. //        Ñ ~AcereApp
  139. // ---------------------------------------------------------------------------
  140. //    Destructor
  141.  
  142. AcereApp::~AcereApp()
  143. {
  144.         // +++ Add code here to cleanup (if necessary) before quitting
  145.         
  146.     if (aboutBox != nil)
  147.         delete aboutBox;
  148. }
  149.  
  150.  
  151. void AcereApp::StartUp()
  152. {
  153.     theDoc = nil;
  154.     
  155.     ourDoc = (CTextDoc *)MakeNewDocument();
  156. }
  157.  
  158.  
  159. void AcereApp::ProcessNextEvent()
  160. {
  161.     balloonsActive = HMGetBalloons();
  162.     
  163.     ourAvailRam = MaxBlock();
  164.  
  165.     
  166.     LDocApplication::ProcessNextEvent();
  167. }
  168.  
  169. Boolean    AcereApp::AllowSubRemoval(LCommander *inSub)
  170. {
  171.     if (inSub == aboutBox)
  172.         aboutBox = nil;
  173.     
  174.     return (true);
  175. }
  176.  
  177.  
  178. // ---------------------------------------------------------------------------
  179. //        Ñ ObeyCommand
  180. // ---------------------------------------------------------------------------
  181. //    Respond to commands
  182.  
  183. Boolean AcereApp::ObeyCommand(
  184.     CommandT    inCommand,
  185.     void        *ioParam)
  186. {
  187.     Boolean    cmdHandled = true;
  188.     
  189.     switch (inCommand) {
  190.     
  191.         // +++ Add cases here for the commands you handle
  192.         //        Remember to add same cases to FindCommandStatus below
  193.         //        to enable/disable the menu items for the commands
  194.     
  195.         cmdAbout:
  196.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  197.             break;
  198.         default:
  199.             cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  200.             break;
  201.     }
  202.     
  203.     return cmdHandled;
  204. }
  205.  
  206.  
  207. // ---------------------------------------------------------------------------
  208. //        Ñ FindCommandStatus
  209. // ---------------------------------------------------------------------------
  210. //    Pass back status of a (menu) command
  211.  
  212. void
  213. AcereApp::FindCommandStatus(
  214.     CommandT    inCommand,
  215.     Boolean        &outEnabled,
  216.     Boolean        &outUsesMark,
  217.     Char16        &outMark,
  218.     Str255        outName)
  219. {
  220.     outUsesMark = false;
  221.     
  222.     switch (inCommand) {
  223.     
  224.         // +++ Add cases here for the commands you handle
  225.     
  226.         default:
  227.             LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  228.                                 outMark, outName);
  229.             break;
  230.     }
  231. }
  232.  
  233.  
  234. void AcereApp::ShowAboutBox()
  235. {
  236. //    aboutBox = LWindow::CreateWindow(1000, this);
  237.         aboutBox = (LDialogBox *) LDialogBox::CreateWindow(1000, this);
  238.  
  239.  
  240.     LStdButton    *theButton;
  241.     theButton = (LStdButton*) aboutBox->FindPaneByID('ok  ');
  242.     theButton->AddListener(this);
  243.  
  244.     aboutBox->Show;
  245.     
  246. }
  247.  
  248. void AcereApp::ListenToMessage(MessageT inMessage, void *ioParam)
  249. {
  250.     if (inMessage == pressedOK)
  251.     {
  252.         delete aboutBox;
  253.     }
  254. }
  255.  
  256.  
  257. // ---------------------------------------------------------------------------
  258. //        Ñ OpenDocument
  259. // ---------------------------------------------------------------------------
  260. //    Open a Document file
  261.  
  262. void
  263. AcereApp::OpenDocument(
  264.     FSSpec    *inMacFSSpec)
  265. {
  266.     CTextDoc *aDoc = new CTextDoc(this, inMacFSSpec);
  267. }
  268.  
  269.  
  270. // ---------------------------------------------------------------------------
  271. //        Ñ MakeNewDocument
  272. // ---------------------------------------------------------------------------
  273. //    Create a new Document
  274.  
  275. LModelObject*
  276. AcereApp::MakeNewDocument()
  277. {
  278.     if (ourDoc == nil)
  279.     {
  280.         ourDoc = new CTextDoc(this, nil);
  281.     }
  282.     else
  283.     {
  284.         ourDoc->StartNewGame(false);
  285.     }
  286.     return ourDoc;
  287. }
  288.  
  289.  
  290. // ---------------------------------------------------------------------------
  291. //        Ñ ChooseDocument
  292. // ---------------------------------------------------------------------------
  293. //    Prompt the user to select a document to open
  294.  
  295. void
  296. AcereApp::ChooseDocument()
  297. {
  298.     StandardFileReply    macFileReply;
  299.     SFTypeList            typeList;
  300.     
  301.     UDesktop::Deactivate();
  302.     typeList[0] = 'TEXT';
  303.     ::StandardGetFile(nil, 1, typeList, &macFileReply);
  304.     UDesktop::Activate();
  305.     if (macFileReply.sfGood) {
  306.         OpenDocument(&macFileReply.sfFile);
  307.     }
  308. }
  309.